package com.dalin.framework.common.pager;

import com.dalin.framework.common.pager.PageQuery;

import java.util.ArrayList;
import java.util.List;

/*****************************************************************************
 * @content: 分页查询条件基类                                                 *
 * @author : 那建林                                                          *
 * @crtDate: 2009-05-07                                                     *
 * @version: 1.0                                                            *
 ****************************************************************************/
public abstract class Condition implements java.io.Serializable {
	private String baseQueryStr; // HQL查询语句
	private String countName;
	private List<Paras> paramList; // 参数集合
	private List<Paras> orParamList; // 参数集合
	private String groupBy; // order by　字段
	private String orderBy; // order by　字段
	private Integer startRow; // 分页起始查询地址
	private Integer pageSize; // 每页显示的行数
	
	private PageQuery pageQuery; // 查询封装类
	
	/*************************************************************************
	 * 组织查询条件
	 */
	public PageQuery getPreparedPageQuery(){
		pageQuery = new PageQuery(startRow, pageSize);
		pageQuery.setBaseQueryStr(baseQueryStr);
		pageQuery.setParamList(paramList);
		pageQuery.setOrParamList(orParamList);
		pageQuery.setGroupBy(groupBy);
		pageQuery.setOrderBy(orderBy);
		return pageQuery;
	}
	

	/*************************************************************************
	 * @content: 设置具体查询参数
	 * @param  : 参数对应数据库字段
	 * @param  : 参数值
	 * @author : 那建林                                   
	 * @crtDate: 2009-05-07  
	 */
	protected void setParam(String pName, String pOperation, Object pValue) {
		Paras p = new Paras();
		p.setPName(pName);
		p.setPOperation(pOperation);
		p.setPValue(pValue);
		paramList.add(p);
	}
	
	protected void setBetweenParam(
			String pName, Object pValue1, Object pValue2) {
		Paras p = new Paras();
		p.setPName(pName);
		p.setPOperation(">=");
		p.setPValue(pValue1);
		paramList.add(p);
		
		p = new Paras();
		p.setPName(pName);
		p.setPOperation("<");
		p.setPValue(pValue2);
		paramList.add(p);
	}

	protected void setOrParam(String pName, String pOperation, Object pValue) {
		Paras p = new Paras();
		p.setPName(pName);
		p.setPOperation(pOperation);
		p.setPValue(pValue);
		orParamList.add(p);
	}
	protected void setOrParamList(String pName, String pOperation, List dataList) {
		for (Object obj : dataList) {
			Paras p = new Paras();
			p.setPName(pName);
			p.setPOperation(pOperation);
			p.setPValue(obj);
			orParamList.add(p);
		}
	}
	
	
	/*************************************************************************
	 * 以下是bean属性的get/set方法
	 */
	public String getBaseQueryStr() {
		return baseQueryStr;
	}

	public void setBaseQueryStr(String baseQueryStr) {
		this.baseQueryStr = baseQueryStr;
		paramList = new ArrayList<Paras>();
		orParamList = new ArrayList<Paras>();
		this.countName = null;
		this.groupBy = null;
		this.orderBy = null;
	}



	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

	public Integer getStartRow() {
		return startRow;
	}

	public void setStartRow(Integer startRow) {
		this.startRow = startRow;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public PageQuery getPageQuery() {
		return pageQuery;
	}

	public void setPageQuery(PageQuery pageQuery) {
		this.pageQuery = pageQuery;
	}
	public String getGroupBy() {
		return groupBy;
	}
	public void setGroupBy(String groupBy) {
		this.groupBy = groupBy;
	}
	public String getCountName() {
		return countName;
	}
	public void setCountName(String countName) {
		this.countName = countName;
	}
}
